﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using System.Windows.Controls;

namespace SuperKnowledgeDatabase2000Client
{
    public class StarWidthConverter : IMultiValueConverter
    {
        /// <summary>
        /// handles window scaling of the GUI
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            ListView listview = value[1] as ListView;           
            double width = listview.ActualWidth;
            GridView gv = listview.View as GridView;
            for (int i = 0; i < gv.Columns.Count; i++)
            {
                if (!Double.IsNaN(gv.Columns[i].ActualWidth) && i != 0)
                    width -= gv.Columns[i].ActualWidth;
            }
            return width-6;
        }

        /// <summary>
        /// resets the window scaling
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
        {
            return new object[] { 0 }; 
        }
    }
}
